package com.example.wangfanwangluo.wangfanboss.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.wangfanwangluo.wangfanboss.Models.FacheModel;
import com.example.wangfanwangluo.wangfanboss.R;

import java.util.List;

/**
 * Created by wanghouyi on 2017/11/28.
 */

public class FacheAdapter extends BaseAdapter {

    private Context context;
    private List<FacheModel> list;
    public FacheAdapter(Context context,List<FacheModel> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public FacheModel getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        FacheModel model = getItem(position);
        View view;
        ViewHolder viewHolder;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.adapter_fache, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.trucksID = (TextView)view.findViewById(R.id.fache_id);
            viewHolder.fromPlace = (TextView)view.findViewById(R.id.fache_place_from);
            viewHolder.toPlace = (TextView)view.findViewById(R.id.fache_place_to);
            viewHolder.driverName = (TextView)view.findViewById(R.id.fache_driver);
            viewHolder.time = (TextView)view.findViewById(R.id.fache_time);
            viewHolder.cost = (TextView)view.findViewById(R.id.fache_cost);
            viewHolder.mobile = (TextView)view.findViewById(R.id.fache_phone);
            viewHolder.status = (TextView)view.findViewById(R.id.fache_status);
            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (ViewHolder)view.getTag();
        }

        viewHolder.trucksID.setText("车牌号"+model.getTrucksID());
        viewHolder.fromPlace.setText(model.getFromPlace());
        viewHolder.toPlace.setText(model.getToPlace());
        viewHolder.driverName.setText("司机姓名："+model.getDriverName());
        viewHolder.time.setText("发车时间："+model.getTime());
        viewHolder.cost.setText("总运费：￥"+model.getCost());
        viewHolder.status.setText("【"+model.getStatus()+"】");
        viewHolder.mobile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FacheModel model = getItem(position);
                objOnCallDriverAction.onCallDriverAction(model.getMobile());
            }
        });



        return view;
    }

    public interface onCallDriverAction {
        void onCallDriverAction(String i);
    }

    private onCallDriverAction objOnCallDriverAction;

    public void setObjOnCallDriverAction(onCallDriverAction objOnDetailPushListener) {
        this.objOnCallDriverAction = objOnDetailPushListener;
    }

    class ViewHolder {
        TextView trucksID;
        TextView fromPlace;
        TextView toPlace;
        TextView driverName;
        TextView time;
        TextView cost;
        TextView status;
        TextView mobile;
    }

}
